package com.llmm.eduService.controller;

import com.llmm.bean.RestRet;

import com.llmm.eduService.entity.UserMember;
import com.llmm.eduService.entity.vo.RegisterVo;
import com.llmm.eduService.service.UserCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/edu/userCenter")
public class UserCenterController {
    @Autowired
    private UserCenterService userCenterService;


    // 登录
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public RestRet<String> loginUser(@RequestBody UserMember member){
        String login = userCenterService.login(member);
        return new RestRet<>(login,0,null);
    }

    //注册
    @PostMapping("register")
    public RestRet<Boolean> registerUser(@RequestBody RegisterVo registerVo) {

        Boolean register = userCenterService.register(registerVo);
        return new RestRet<>(register,0,null);
    }

    // 根据token获取用户信息。
    @GetMapping("getUserInfo")
    public RestRet<UserMember> getUserInfo(HttpServletRequest request){

        UserMember userInfo = userCenterService.getUserInfo(request);
        return new RestRet<>(userInfo,0,null);

    }

}
